package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;

/**
 * INSERT 语句使用预编译SQL
 */
public class JDBCDemo9 {
    public static void main(String[] args) {
        //向user表中插入一条记录
        try(Connection connection=DBUtil.getConnection();) {
            String sql = "UPDATE userinfo " +
                    "SET password=?,nickname=?,age=? " +
                    "WHERE id=?";
            PreparedStatement ps = connection.prepareStatement(sql);
            ps.setString(1,"");
            ps.setString(2,"");
            ps.setInt(3,33);
            ps.setInt(4,2);

           int num= ps.executeUpdate();
           System.out.println(num>0?"插入成功":"插入失败");

        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
